package com.tdzx.ui;


import com.tdzx.R;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;


/**
 * 
 * @author utopia
 *
 */
public class PreferentialActivity extends BaseActivity_NoBar {
	String preferential = "广告详情页";
	TextView merName;
	ImageView caterory_back;
	ImageView cat_src;
	
	WebView pref;
	
//	ADEntivity entity;
	
	String url = "";
	String name = "";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.preferentia);
		Intent intent = getIntent();
//		entity = (ADEntivity) intent.getSerializableExtra("entity");
		url = intent.getStringExtra("url");
		name = intent.getStringExtra("name");
		
		initView();
		pref = (WebView) findViewById(R.id.preferential);
		pref.getSettings().setJavaScriptEnabled(true);
		pref.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				pref.loadUrl(url);
				return super.shouldOverrideUrlLoading(view, url);
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				finishProgress();
				super.onPageFinished(view, url);
			}
			
		});
		
		showProgress("正在加载中...");
		pref.loadUrl(url);
		
		merName = (TextView) findViewById(R.id.merName);
		merName.setText(name);
	}
	
	
	@Override
    public void onBackPressed() {
        if (pref.canGoBack()) {
        	pref.goBack();
        } else {
            super.onBackPressed();
        }
    }
	
	private void initView() {
		caterory_back = (ImageView) findViewById(R.id.caterory_back);
		caterory_back.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				Log.i("ccc", "onTouch ca");
				cat_src.onTouchEvent(arg1);
				return false;
			}
		});
		
		caterory_back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		
		cat_src = (ImageView) findViewById(R.id.cat_src);
		cat_src.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				Log.i("ccc", "onTouch crc");
				return true;
			}
		});
	}
}
